// pages/movie/movie.js
const app = getApp() //导出数据
let utils=require("../../utils/util.js")
// let utils = require("../movie/more/more-grid/more-grid.wxml")

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log("app.globalurl.globa", app.globalurl.globa)
    let sp ="林俊杰"
    var that = this;
    this.http(sp, that.cak,'author')
  },
  http(data, cak,category){
    var that = this;
    wx.request({
      url: app.globalurl.globa + '/music/api/?key=523077333&cache=1&type=so&id='+data+'&size=hq',
      data: {
        x: '',
        y: ''
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log(res)
        that.cak(res.data, category)
      }
    })
  },
  cak(res, category){
    console.log(res)
    let moview=[]
    for (let idx in res.Body){
      let subject = res.Body[idx]
      let title = subject.title
      if (title.length>=6){ title=title.substring(0,6)+"..."}
      let covimg = subject.pic
      let author = subject.author
      let ping = subject.size128
      let statr = utils.conver(ping)
      let aid = subject.vid
      let temp={
        title:subject.title,
        covimg:subject.pic,
        author: author,
        statr: utils.conver(subject.size128),
        ping: ping,
        aid:subject.vid
      }
      moview.push(temp)
    }
    let readydata={}
    readydata[category]={
      moview: moview
    }
    console.log(readydata)
    this.setData(readydata)
    this.setData({
      data1: readydata.author.moview.slice(0,3)
    })
    this.setData({
      data2: readydata.author.moview.slice(3, 6)
    })
    this.setData({
      data3: readydata.author.moview.slice(6, 9)
    })
    
  },

  /**.Body
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  movietab(e){
    console.log(e.currentTarget.dataset.catrgory)
    let cata = e.currentTarget.dataset.catrgory
    wx.navigateTo({
      url: '../movie/more/more?catrgory='+cata,
    })
  }
})